﻿using System;
using System.Threading;
using System.Windows.Forms;

namespace PhiStore.Experiments
{
    public partial class ExperimentsUI : Form
    {
        public ExperimentsUI()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Serialize.SerializeExperiment exp = new Serialize.SerializeExperiment(750000);
            RunExperiment(exp);
        }

        private void RunExperiment(IExperiment experiment)
        {
            PhiStore.Threading.Booster.Boost(experiment);
            while (!experiment.IsComplete())
            {
                textBox1.Text = "Running...";
                textBox1.Update();
                Thread.Sleep(1000);
            }

            textBox1.Text = experiment.getResults();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Compression.CompressionExperiment exp = new Compression.CompressionExperiment(1024 * 1024*100, Randomize.Checked, int.Parse(BufferSize.Text));
            RunExperiment(exp);
        }

        private void button3_Click(object sender, EventArgs e)
        {
            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                Compression.CompressionExperiment exp = new Compression.CompressionExperiment(openFileDialog.FileName, int.Parse(BufferSize.Text));
                RunExperiment(exp);
            }
        }

        private void Encryption_Click(object sender, EventArgs e)
        {
            Experiments.Encryption.EncryptionExperiment exp = new Experiments.Encryption.EncryptionExperiment();
            RunExperiment(exp);
        }

        private void Base64_Click(object sender, EventArgs e)
        {
            Experiments.Base64.Base64Experiment exp = new Base64.Base64Experiment();
            RunExperiment(exp);
        }

    }
}
